package com.situ.mymall.controller;

import com.situ.mymall.pojo.entity.Shipping;
import com.situ.mymall.pojo.entity.User;
import com.situ.mymall.pojo.query.ShippingQuery;
import com.situ.mymall.service.IShippingService;
import com.situ.mymall.util.Result;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shipping")
public class ShippingController {

    @Autowired
    private IShippingService shippingService;

    @RequestMapping("/list")
    public Result list(ShippingQuery shippingQuery, HttpSession session){
        User user = (User) session.getAttribute("user");
        shippingQuery.setUserId(user.getId());
        List<Shipping> list = shippingService.list(shippingQuery);
        return Result.ok(list);
    }

    @RequestMapping("/add")
    public Result add(Shipping shipping,HttpSession session){
        User user = (User) session.getAttribute("user");
        shipping.setUserId(user.getId());
        shippingService.add(shipping);
        return Result.ok("地址添加成功");
    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(Shipping shipping){
        shippingService.updateStatus(shipping);
        return Result.ok("更新成功");
    }

    @RequestMapping("/deleteByStatusUserId")
    public Result deleteByStatusUserId(Shipping shipping,HttpSession session){
        User user = (User) session.getAttribute("user");
        shipping.setUserId(user.getId());
        shippingService.deleteByStatusUserId(shipping);
        return Result.ok("成功删除默认地址");
    }




}
